package Demo1;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 34255
 * Date: 2024-06-05
 * Time: 16:55
 */
public class A {

}
class B extends A{
    String name = "小B";
}
class C extends A{
    String name = "小C";
}

class Demo{
    public static void func(A ret){
        if(ret instanceof C result){
            System.out.println(result.name);
        }
    }
    public static void func1(A ret){
        if(ret instanceof B){
            B ret1 = (B)ret;
            System.out.println(ret1.name);
        }
    }
    public static void main(String[] args) {
        func(new C());
    }
}


